<?php
/**
 * 用户晒单类
 */
class SunsingleController extends UserLoginBaseC{
	public function actionIndex(){
		if(IS_POST){
			yii::import('ext.yzwAPI.*');
			if(!DzAPI::getInstance()->canSunsingle()){
				$this->error('请先到论坛激活账号再晒单');
			}			
			$objModel = new MembersSunsingleModel('create');
			$objModel->attributes = $_POST;
			$objModel->uid = yii::app()->user->uid;
			if($objModel->save()){
				$objSalesModel = SalesDataModel::model()->find(array('condition' => 'orders_number = :orders_number', 'params' => array('orders_number' => $objModel->ordersn)));
				if($objSalesModel){//在销售数据里面能找到此订单记录
					if($objModel->post($objSalesModel)){
						$objModel->status = 1;//处理成功
						$objModel->save(false,array('status'));
						$this->success('成功晒单');
					}else{
/*						$key = 'members_sunsingle';
						$id = $objModel->id;
						$infoList = RedisCluster::getInstance()->push($key, $id);*/
						$this->success('提交成功,3天内给处理结果,请留意系统通知');
						//exit('找到记录但晒单失败');				
					}
				}else{
/*					$key = 'members_sunsingle';
					$id = $objModel->id;
					$infoList = RedisCluster::getInstance()->push($key, $id);*/
					$this->success('提交成功,3天内给处理结果,请留意系统通知');					
					//exit('找不到此订单信息');
				}
			}else{
				$this->error($objModel->getOneError());
			}
		}
		$this->render('index');   		
	}

	public function actionList(){
        $objModel = new MembersSunsingleModel('search');
        $objModel->resetAttributes();
        if(isset($_GET['MembersSunsingleModel']))
        {
            $objModel->attributes = $_GET['MembersSunsingleModel'];
        }

        //增加搜索条件
        $objModel->uid = yii::app()->user->id;
        //创建搜索
        $objCriteria = $objModel->createSearchCriteria(); 

        //分页
		$intCount = $objModel->count($objCriteria);
        $objPager = new CPagination($intCount);
        $objPager->pageSize = 10;
        $objPager->applyLimit($objCriteria);

       //排序
        $objSort = new CSort('MembersSunsingleModel');
        $objSort->defaultOrder = 'status DESC';
        $objSort->applyOrder($objCriteria);


        $objModels = $objModel->findAll($objCriteria);
        $this->assign('pages', $objPager);
        $this->assign('sort', $objSort);
        $this->assign('model', $objModel); 
        $this->assign('models', $objModels);
        $this->render('list');  		
	}
}